package com.example.user.service;


import com.example.user.common.Result;
import com.example.user.entity.User;
import com.example.user.mapper.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserInfoService {


    @Autowired
    private UserInfoMapper userMapper;

    public Result register(User user) {

       User userInfo= userMapper.selectUser(user);
       if(userInfo!=null){
           if(userInfo.getUsername()!=null&&userInfo.getPassword()!=null)
           {
               return Result.error("400","以及被注册");
           }

       }
      int count= userMapper.register(user);
       if(count==0)
       {
           return Result.error("400","注册失败");
       }
       return Result.success("注册成功");
    }

    public Result login(User user) {

        User userInfo= userMapper.selectUser(user);
        if(userInfo!=null){
            return Result.success("登录成功");
        }
        return Result.error("400","查无此用户");
    }
}
